package com.RedRiver.hospitalsystem.record_service.app.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liuzhao
 * @ClassName TokenGet
 * @Date 2022/4/8 12:09
 * @since 2022-03-23
 */
@Component
public class TokenGet {

    @Resource
    private TokenTemplate tokenTemplate;

    //获取用户Id
    public Integer getAccountId() {

        String header = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("UserToken");
        System.out.println(header);
        Object accountId = tokenTemplate.parseToken(header).get("accountId");
        return (Integer) accountId;
    }

    public String getAccountName() {
        String header = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("UserToken");
        return tokenTemplate.parseToken(header).get("accountName").toString();
    }
}
